<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
 Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="editorDocument.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>editorDocument.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'editorDocument.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="editorDocument.html">editorDocument</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * A document where someone can add and set EOs. It represents all the content built in an edition area.
 * <span class="attrib">@author</span> Roosevelt de Lima Sardinha
 * <span class="attrib">@param</span> {Object} json Optional JSON to build the document.
 * <span class="attrib">@constructor</span>
 */</span>
<span class="reserved">function</span> editorDocument(json){
	<span class="comment">/**
	 * The unique id of the document.
	 * <span class="attrib">@type</span> {Int}
	 */</span>
    <span class="reserved">this</span>.id = null;
	
	<span class="comment">/**
	 * The name of the document.
	 * <span class="attrib">@type</span> {String}
	 */</span>
	<span class="reserved">this</span>.name = null;
	
	<span class="comment">/**
	 * The description of the content of the document.
	 * <span class="attrib">@type</span> {String}
	 */</span>
	<span class="reserved">this</span>.description = null;
	
	<span class="comment">/**
	 * The editionArea where this document is opened.
	 * <span class="attrib">@type</span> {Object}
	 */</span>
	<span class="reserved">this</span>.editionArea = null;
	var myJSON = null;
	<span class="reserved">if</span> (json != null){
		myJSON = json;
	}

	<span class="comment">/**
	 * Opens the content of a document in a edition area.
	 * <span class="attrib">@param</span> {Object} editionArea The edition area where the content is going to be added.
	 */</span>
    <span class="reserved">this</span>.open = <span class="reserved">function</span>(editionArea){
		<span class="reserved">if</span> (<span class="reserved">this</span>.id != null) {
			var docJSON = <span class="reserved">this</span>.generateJSONfromDB();
			myJSON = docJSON;
		}
		
		<span class="reserved">if</span> (myJSON != null){
			editionArea.EOM.createEOsByJSON(myJSON);
		}
		
		<span class="reserved">this</span>.editionArea = editionArea;
    }
    
	<span class="comment">/**
	 * Saves the content of a document to the database.
	 */</span>
    <span class="reserved">this</span>.save = <span class="reserved">function</span>(){
		var exists = null;
		var id;
    	var EOsJSON = <span class="reserved">this</span>.editionArea.EOM.EO_JSON();
		var docJSON = {};
		docJSON.name = <span class="reserved">this</span>.name;
		docJSON.description = <span class="reserved">this</span>.description;
		docJSON.eos = EOsJSON;
		
		var strJSON = JSON.stringify(docJSON);
						
		var params = [];
		params[<span class="literal">'json'</span>] = strJSON;
				
		var myRequest = new request();	
		<span class="reserved">if</span> (<span class="reserved">this</span>.id != null) {
			myRequest.sendSincRequest(<span class="literal">'GET'</span>, null, <span class="literal">"documents/"</span> + <span class="reserved">this</span>.id + <span class="literal">"/exist"</span>, <span class="reserved">function</span>(response){
				exists = response;
			});
		}
		
		<span class="comment">// Check if document already exists</span>
		<span class="reserved">if</span> ((exists != null) &amp;&amp; JSON.parse(exists)){
			params[<span class="literal">'_method'</span>] = <span class="literal">'PUT'</span>;
	        myRequest.sendSincRequest(<span class="literal">'POST'</span>, params, <span class="literal">"documents/"</span> + <span class="reserved">this</span>.id, <span class="reserved">function</span>(response){
			});
		}<span class="reserved">else</span>{
	        myRequest.sendSincRequest(<span class="literal">'POST'</span>, params, <span class="literal">"documents"</span>, <span class="reserved">function</span>(response){
				id = response;
			});
			<span class="reserved">this</span>.id = JSON.parse(id);		
		}	
    }
	
	<span class="comment">/**
	 * Generates a JSON corresponding to the document.
	 * <span class="attrib">@return</span> A JSON describing this document.
	 * <span class="attrib">@type</span> {Object}
	 */</span>
	<span class="reserved">this</span>.generateJSON = <span class="reserved">function</span>(){
		var EOsJSON = <span class="reserved">this</span>.editionArea.EOM.EO_JSON();
		docJSON = {};
		docJSON.name = <span class="reserved">this</span>.name;
		docJSON.description = <span class="reserved">this</span>.description;
		docJSON.eos = EOsJSON;
		<span class="reserved">return</span> docJSON;
	}
    
	<span class="comment">/**
	 * Generates a JSON from the content in the database corresponding to the document. Maybe not what is on the screen in the edition area.
	 * To update these data you need to save the document
	 * <span class="attrib">@return</span> A JSON describing the document.
	 * <span class="attrib">@type</span> {Object}
	 */</span>    
    <span class="reserved">this</span>.generateJSONfromDB = <span class="reserved">function</span>(){
    	var EOsStr;
        var myRequest = new request();
        myRequest.sendSincRequest(<span class="literal">'GET'</span>, null, <span class="literal">"documents/"</span> + <span class="reserved">this</span>.id, <span class="reserved">function</span>(response){
            EOsStr = response;
        });
		var EOsJSON = JSON.parse(EOsStr);
		<span class="reserved">return</span> EOsJSON;
    }
    
	<span class="comment">/**
	 * Generates a XML from the content of the document.
	 * <span class="attrib">@return</span> The XML corresponding to the document.
	 * <span class="attrib">@type</span> {String}
	 */</span>
    <span class="reserved">this</span>.generateXML = <span class="reserved">function</span>(){
    	var EOsStr;
        var myRequest = new request();
        myRequest.sendSincRequest(<span class="literal">'GET'</span>, null, <span class="literal">"documents/"</span> + <span class="reserved">this</span>.id  + <span class="literal">".xml"</span>, <span class="reserved">function</span>(response){
            EOsStr = response;
        });
		<span class="reserved">return</span> EOsStr;    
    }
    
	<span class="comment">/**
	 * Generates a HTML from the content of the document.
	 * <span class="attrib">@return</span> The HTML corresponding to the document.
	 * <span class="attrib">@type</span> {String}
	 */</span>
    <span class="reserved">this</span>.generateHTML = <span class="reserved">function</span>(){
		var ind = new indenter();
    	<span class="reserved">return</span> ind.indentHTML(<span class="reserved">this</span>.editionArea.EOM.getEOsHTML());
    }
    
	<span class="comment">/**
	 * Changes a property of the document to some value
	 * <span class="attrib">@param</span> {String} propertyName The name of the property to be changed.
	 * <span class="attrib">@param</span> {Any} value The value to be set to the property.
	 */</span>		
    <span class="reserved">this</span>.setProperty = <span class="reserved">function</span>(property, value){
    	switch(property){
			case <span class="literal">'name'</span>:
				<span class="reserved">this</span>.name = value;
				break;
				
			case <span class="literal">'description'</span>:
				<span class="reserved">this</span>.description = value;
				break;
				
			default:				
		}
    }
		
	<span class="comment">/**
	 * Closes a document previously opened. Removes all EOs of the edition Area and sets this document edition area property to null.
	 */</span>
	<span class="reserved">this</span>.close = <span class="reserved">function</span>(){
		<span class="reserved">this</span>.editionArea.EOM.removeAllEOs();
		<span class="reserved">this</span>.editionArea = null;
	}	
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Mon Feb 21 18:12:28 2011</div>
</body>
</html>
